package zh.dummy.netty.support;

import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import zh.dummy.netty.client.context.NettyManager;
import zh.dummy.netty.client.context.listener.WorkflowListener;

public class NettyClientStartTrigger{

	private Logger logger = LoggerFactory.getLogger(getClass());
	
	private String host;
	
	private int port;
	
	private Set<WorkflowListener> listeners;
	
	private WorkflowListener listener;
	
	private String clientId;

	public void init() {
		if(logger.isInfoEnabled()){
			logger.info("start initial netty client");
		}
		NettyManager nettyManager = NettyManager.getInstance();
		nettyManager.setHost(host);
		nettyManager.setPort(port);
		if(listeners!=null){
			nettyManager.setWorkflowListeners(listeners);
		}
		if(listener != null){
			nettyManager.setWorkflowListener(listener);
		}
		nettyManager.setClientId(clientId);
		nettyManager.startNettyClient();
	}
	
	public void destroy(){
		if(logger.isInfoEnabled()){
			logger.info("destroyed netty client");
		}
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public Set<WorkflowListener> getListeners() {
		return listeners;
	}

	public void setListeners(Set<WorkflowListener> listeners) {
		this.listeners = listeners;
	}

	public String getClientId() {
		return clientId;
	}

	public void setClientId(String clientId) {
		this.clientId = clientId;
	}

	public WorkflowListener getListener() {
		return listener;
	}

	public void setListener(WorkflowListener listener) {
		this.listener = listener;
	}
	
	public static void main(String[] args) {
		new NettyClientStartTrigger().init();
	}
	
}
